<template>
    <div class="pushList">
        <el-row style="text-align:right;margin: 10px 0">
            <el-button type="primary" @click="add">新建推送</el-button>
        </el-row>
        <el-row>
            <el-table :data="noticeData" style="width: 100%" border>
                <el-table-column type="index" label="序号" width="200" align="center" :index="indexSort">
                </el-table-column>
                <el-table-column prop="title" label="标题" align="center">
                </el-table-column>
                <el-table-column prop="platform" label="平台名" align="center">
                </el-table-column>
                 <el-table-column style="" prop="createDate" label="发送时间" align="center">
                </el-table-column>
                 <el-table-column prop="intentUrl" label="跳转路径" align="center">
                </el-table-column>
                <el-table-column prop="content" label="内容" align="center">
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <span class="el-tag el-tag--primary el-tag--small" style="cursor: pointer;" @click="cancel(scope.row)" size="mini">
                            撤销
                        </span>
                    </template>
                </el-table-column>
            </el-table>
        </el-row>
        <el-row style="text-align: right;">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[15, 50, 100, 200]"
                :page-size="pageSize"
                layout="->, sizes, prev, pager, next, jumper, total"
                :total="totalElements"
            ></el-pagination>
        </el-row>
        <addPush :off.sync="pushDialog" :rowData="rowdata"></addPush>
    </div>
</template>

<script>
    import { getPushList,cancelPush } from "@/api/supermarket/push.js"
    import * as util from "@/util/util.js"
    export default {
        name: "pushList",
        components: {
            "addPush": () => import("@/views/goodsSupermarket/companyPush/addPush")
        },
        data(){
            return {
                noticeData: [],
                pageSize: 15,
                currentPage: 1,
                totalElements: 0,
                totalPages: 1,
                pushDialog: false,
                rowdata: {}
            }
        },
        created(){
            this.getList();
        },
        methods: {
            add(){
                this.pushDialog = true;
            },
            cancel(row){
                console.log("row", row);
                cancelPush({infoId: row.infoId}).then(
                    res => {
                        console.log("-----");
                        // if(res.code == 400){
                        //     this.$notify.error(res.msg);
                        // }else{
                        //     this.$notify.success("撤销成功");
                        // }
                    },
                    err => {}
                );
            },
            getList(){
                 getPushList({
                    currentPage: this.currentPage,
                    pageSize: this.pageSize,
                    type: 1
                }).then(
                    res => {
                        console.log("res公司推送接口", res);
                        this.noticeData = res.data.list;
                        this.noticeData.forEach((e) => {
                            e.createDate = util.timestampToTime(e.createDate);
                            if(e.notificationType == 1){
                                e.notificationType = "店铺平台通知";
                            }else{
                                e.notificationType = "区域平台通知";
                            }
                        });
                        this.totalElements = res.data.total;
                    },
                    err => {}
                );
            },
            //序号
            indexSort(index) {
                if (this.currentPage > 1) {
                    index = (this.currentPage - 1) * this.pageSize + index + 1;
                } else {
                    index = index + 1;
                }
                return index;
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.getList();
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.getList();
                console.log(`当前页: ${val}`);
            }
        }
    }
</script>

<style lang="less" props>
.pushList {

}
</style>